<%-- 
    Document   : AgregarProyecto
    Created on : Feb 8, 2013, 9:38:41 PM
    Author     : alumnos
--%>
<%@page import="beans.producto"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>

        <LINK REL=StyleSheet href="style/Estilos.css" TYPE="text/css" />



        <script>
            
            function cerrar(){
                
                
     
                window.opener.parent.f_listar();
                window.close();
           
                 
                
            }
            
            function f_modificar(){

                var context = "<%= request.getContextPath()%>";
                
                var boo = validar();
                
                if(boo == false)
                    return false;  
              
                document.form1.hValor.value = "mg";
                document.form1.action = context+"/Buscarproducto";
                document.form1.method="POST";
                document.form1.submit();
                
            }
        
            function validar(){
            
                var frm = document.getElementById("form1");
                for (i=0;i<frm.elements.length;i++)
                {

                    if(frm.elements[i].type == "text" ){
                    
                        if(frm.elements[i].value == ""){
                        
                            var txtnombre = frm.elements[i].name.substr(3);
                        
                            alert("El campo  " + txtnombre + " esta vacio");
                            return false;
                        }
                        
                      
                    }
         
                }
            
                return true;
            
            }
        
            function f_grabar(){
            
                var boo = validar();
                
                if(boo == false)
                    return false;
            
                var context = "<%= request.getContextPath()%>";
              
                document.form1.hValor.value = "gr";
  
                
                document.form1.action = context+"/Buscarproducto";
                document.form1.method="POST";
                document.form1.submit();
                
            }
            
            function f_habilitar(boo){
                
                var frm = document.getElementById("form1");
                for (i=0;i<frm.elements.length;i++)
                {
                    //alert(frm.elements[i].name);
                    //alert(frm.elements[i].type);
                    //alert(frm.elements[i].value);
                    
                    //alert(frm.elements[i].alt);
                    
                    if(frm.elements[i].type == "text" && frm.elements[i].alt != 'S' ){
                        frm.elements[i].readOnly = boo;
                    
                        if(boo == true)
                            frm.elements[i].className = 'deshabilidato'
                        else
                            frm.elements[i].className = 'habilidato'    
                        //alert(frm.elements[i].value);
                     
                    }
                        
                    
                }
        
                var btnHabilitar = document.getElementById("btnHabilitar");
                var btnCancelar = document.getElementById("btnCancelar");
                var btnGrabar = document.getElementById("btnGrabar");
            
                btnHabilitar.disabled = true;
                btnCancelar.disabled = false;
                btnGrabar.disabled = false;
            
                
            }
        
            function f_cancelar(){
            
                f_habilitar(true);
            
                var btnHabilitar = document.getElementById("btnHabilitar");
                var btnCancelar = document.getElementById("btnCancelar");
                var btnGrabar = document.getElementById("btnGrabar");
            
                btnHabilitar.disabled = false;
                btnCancelar.disabled = true;
                btnGrabar.disabled = true;
            
            }
        
            
            function soloInt(evt)
            {
                var charCode = (evt.which) ? evt.which : event.keyCode
                if (charCode > 31 && (charCode < 48 || charCode > 57))
                    return false;
 
                return true;
            }
        
            function soloDouble(evt)
            {
                var charCode = (evt.which) ? evt.which : event.keyCode
                if (charCode > 31 && (charCode < 48 || charCode > 57))
                    return false;
 
                return true;
            }
            

            
        </script>   

    </head>
    <body>
        <div id="stylized" class="myform"  >
            <form id="form1" name="form1" method="post" action="" >


                <% if (request.getAttribute("cerrar") != null) {
                    if (request.getAttribute("cerrar") == "S") {%>
                if (request.getAttribute("cerrar") != null)
                <script language='JavaScript' type='text/javascript'>
                    cerrar();  
                </script>
                <% } else {%>
                <font color="red" >Error al modificar</font>

                <%  }
                }%>

                <%
                    if (request.getAttribute("Producto") != null) {

                        producto bean = (producto) request.getAttribute("Producto");



                %>
                <div style="width: 100%;height: 300px;overflow: auto;" >    
                    <table>

                        <tr>
                            <td>
                                <h1>Modificar</h1>
                            </td>
                        </tr>

                        <tr>
                            <td>
                                id
                            </td>
                            <td>
                                <input alt="S" class="deshabilidato" type="text" onkeypress="return soloInt(event)" name="txtPRODUCT_ID" id="txtPRODUCT_ID" value="<%= bean.getPRODUCT_ID()%>" readonly="true"   /> 
                            </td>
                        </tr>
                        <tr>
                            <td>
                                getMANUFACTURER_ID
                            </td>
                            <td>
                                <input alt="S" class="deshabilidato" type="text" onkeypress="return soloInt(event)" name="txtMANUFACTURER_ID" id="txtMANUFACTURER_ID" value="<%= bean.getMANUFACTURER_ID()%>" readonly="true" /> 
                            </td>
                        </tr>
                        <tr>
                            <td>
                                PRODUCT_CODE
                            </td>
                            <td>
                                <input alt="S" class="deshabilidato" type="text"  name="txtPRODUCT_CODE" id="txtPRODUCT_CODE" value="<%= bean.getPRODUCT_CODE()%>" readonly="true"  /> 
                            </td>
                        </tr>
                        <tr>
                            <td>
                                PURCHASE_COST
                            </td>
                            <td>
                                <input type="text" class="deshabilidato" onkeypress="return soloDouble(event)" name="txtPURCHASE_COST" id="txtPURCHASE_COST" value="<%= bean.getPURCHASE_COST()%>" readonly="true" /> 
                            </td>
                        </tr>
                        <tr>
                            <td>
                                QUANTITY_ON_HAND
                            </td>
                            <td>
                                <input type="text" class="deshabilidato" onkeypress="return soloInt(event)" name="txtQUANTITY_ON_HAND" id="txtQUANTITY_ON_HAND" value="<%= bean.getQUANTITY_ON_HAND()%>" readonly="true" /> 
                            </td>
                        </tr>
                        <tr>
                            <td>
                                MARKUP
                            </td>
                            <td>
                                <input type="text" class="deshabilidato" onkeypress="return soloDouble(event)" onkeypress="return soloDouble(event)" name="txtMARKUP" id="txtMARKUP" value="<%= bean.getMARKUP()%>" readonly="true" /> 
                            </td>
                        </tr>
                        <tr>
                            <td>
                                AVAILABLE
                            </td>
                            <td>
                                <input type="text" class="deshabilidato" name="txtAVAILABLE"  id="txtAVAILABLE" value="<%= bean.getAVAILABLE()%>" readonly="true" /> 
                            </td>
                        </tr>
                        <tr>
                            <td>
                                DESCRIPTION
                            </td>
                            <td>
                                <input type="text" class="deshabilidato" name="txtDESCRIPTION" id="txtDESCRIPTION" value="<%= bean.getDESCRIPTION()%>" readonly="true" /> 
                            </td>
                        </tr>

                        <tr>
                            <td colspan="2" >
                                <input type="button" id="btnHabilitar" OnClick="f_habilitar(false);" value="editar" />
                                <input type="button" id="btnCancelar" OnClick="f_cancelar();" value="Cancelar" />
                                <input type="button" id="btnGrabar" OnClick="f_modificar();" value="Modificar" disabled="true" />
                            </td>
                        </tr>



                    </table>

                </div>

                <% } else {%>

                <table>

                    <tr>
                        <td>
                            <h1>Agregar</h1>
                        </td>
                    </tr>

                    <tr>
                        <td>
                            PRODUCT_ID
                        </td>
                        <td>
                            <input type="text" name="txtPRODUCT_ID" onkeypress="return soloInt(event)" id="txtPRODUCT_ID" /> 
                        </td>
                    </tr>
                    <tr>
                        <td>
                            MANUFACTURER_ID
                        </td>
                        <td>
                            <input type="text" name="txtMANUFACTURER_ID" onkeypress="return soloInt(event)" id="txtMANUFACTURER_ID"  /> 
                        </td>
                    </tr>
                    <tr>
                        <td>
                            PRODUCT_CODE
                        </td>
                        <td>
                            <input type="text" name="txtPRODUCT_CODE" id="txtPRODUCT_CODE"  /> 
                        </td>
                    </tr>
                    <tr>
                        <td>
                            PURCHASE_COST
                        </td>
                        <td>
                            <input type="text" onkeypress="return soloDouble(event)" name="txtPURCHASE_COST" id="txtPURCHASE_COST"  /> 
                        </td>
                    </tr>
                    <tr>
                        <td>
                            QUANTITY_ON_HAND
                        </td>
                        <td>
                            <input type="text" name="txtQUANTITY_ON_HAND" onkeypress="return soloInt(event)"  id="txtQUANTITY_ON_HAND"  /> 
                        </td>
                    </tr>
                    <tr>
                        <td>
                            MARKUP
                        </td>
                        <td>
                            <input type="text" onkeypress="return soloDouble(event)" name="txtMARKUP" id="txtMARKUP"   /> 
                        </td>
                    </tr>
                    <tr>
                        <td>
                            AVAILABLE
                        </td>
                        <td>
                            <input type="text" name="txtAVAILABLE" id="txtAVAILABLE"  /> 
                        </td>
                    </tr>
                    <tr>
                        <td>
                            DESCRIPTION
                        </td>
                        <td>
                            <input type="text" name="txtDESCRIPTION" id="txtDESCRIPTION"  /> 
                        </td>
                    </tr>

                    <tr>
                        <td colspan="2" >
                            <button type="button" id="btnGrabar1" OnClick="f_grabar();" >Grabar</button>
                        </td>
                    </tr>

                </table>


                <% }%>

                <input type="hidden" id="hValor" name="hValor" />
            </form>

        </div>

    </body>
</html>
